//
//  BRCardListTableViewCell.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/9/30.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRCardListTableViewCell.h"

@implementation BRCardListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.contentBG.backgroundColor = UIColor.whiteColor;
    self.contentBG.layer.cornerRadius = 14;
    self.contentBG.layer.masksToBounds = YES;
    self.cardNumL.textColor = kColorTitle;
    self.cardNumL.font = [UIFont fontS:14];
    self.subTextL.textColor = kColorTitle;
    self.subTextL.font = [UIFont fontM:12];
    self.contentBG.layer.borderWidth = 2;
    self.subTextL.hidden = YES;
}

- (void)setType:(NSInteger)type {
    _type = type;
    
    if (type == 0) {
        self.cardNumL.text = Localized(@"pay_newCardPay");
//        self.cardNumL.textColor = UIColor.qd_tintColor3;
        self.defaultImg.image = UIImageMake(@"arrow_right_gray20");
        self.cardTypeImg.image = UIImageMake(@"pay_add");
        self.contentBG.layer.borderWidth = 0;
//        self.subTextL.hidden = YES;
    }else {
//        self.subTextL.hidden = NO;
        if (type == 3) {
            
            self.cardNumL.text = @"Apple pay";
            self.cardTypeImg.image = UIImageMake(@"card_typeApple");
//            self.subTextL.hidden = YES;
        }
        if (type == 7) {
            
            self.cardTypeImg.image = UIImageMake(@"pay_type7");
            
        }
        if (type == 8) {
            
            self.cardTypeImg.image = UIImageMake(@"pay_type8");
          
        }
        
//        self.cardNumL.textColor = UIColor.qd_titleTextColor;
        self.defaultImg.image = UIImageMake(@"pay_unselected");
    }
}

- (void)setIsSel:(BOOL)isSel {
    _isSel = isSel;

    dispatch_async(dispatch_get_main_queue(), ^{
        if (isSel) {
            self.defaultImg.image = UIImageMake(@"pay_selected");
            self.contentBG.layer.borderColor = UIColorMakeWithHex(@"#E7FF55").CGColor;
        }else {
            self.defaultImg.image = UIImageMake(@"pay_unselected");
            self.contentBG.layer.borderColor = UIColor.whiteColor.CGColor;
        }
    });

}

- (void)setDto:(BRCardModel *)dto {
    _dto = dto;
    
    if ([dto.bankType isEqualToString:@"3"]) {
        self.type  = 3;
    }else if ([dto.bankType isEqualToString:@"7"]) {
        self.type  = 7;
        self.cardNumL.text = dto.bankName;
    }else if ([dto.bankType isEqualToString:@"8"]) {
        self.type  = 8;
        self.cardNumL.text = dto.bankName;
    }else {
        self.type  = 1;
        
        self.cardNumL.text = [NSString stringWithFormat:@"**** **** **** %@",dto.bankNo];
        STPCardBrand cardBrand = [STPCard brandFromString:dto.bankName];
        
        // 修复：// // // STPImageLibrary (已在新版本中移除) (已在新版本中移除) (已在新版本中移除) 在新版本 Stripe 中不存在，使用默认图片或自定义实现
        UIImage *img = nil;
        // 可以根据 cardBrand 设置不同的默认图片
        switch (cardBrand) {
            case STPCardBrandVisa:
                img = [UIImage imageNamed:@"visa_card"] ?: [UIImage systemImageNamed:@"creditcard"];
                break;
            case STPCardBrandMastercard:
                img = [UIImage imageNamed:@"mastercard_card"] ?: [UIImage systemImageNamed:@"creditcard"];
                break;
            case STPCardBrandAmex:
                img = [UIImage imageNamed:@"amex_card"] ?: [UIImage systemImageNamed:@"creditcard"];
                break;
            default:
                img = [UIImage systemImageNamed:@"creditcard"];
                break;
        }
        self.cardTypeImg.image =  img;
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    
}

@end
